class Solution
{
public:
    int multiply(int A, int B)
    {
        if (A < B)
        {
            swap(A, B);
        }

        int result = 0;
        while (true)
        {
            if (B & 1)
            {
                result += A;
            }

            B = B >> 1;
            if (!B)
            {
                break;
            }

            A += A;
        }
        return result;
    }
};